var KOC = require("koc.common.utils");

var Mysql_Helper = null;
var DBName = null;

module.exports = {
    //region 初始化
    Init: function (sql_helper, dbname) {
        if (!Mysql_Helper) {
            Mysql_Helper = sql_helper;
            DBName = dbname;
        }
        return this;
    },
    //endregion
    //region User_Login:用户登录日志
    User_Login: {
        Insert: function (Value, callback) {
            var sql = "INSERT INTO `user_login`" +
                " (`User_ID`" +
                ", `NickName`" +
                ", `RealName`" +
                ", `IsAnchor`" +
                ", `IsFamily`" +
                ", `IsAdmin`" +
                ", `IsIDCard`" +
                ", `IsChargeFirst`" +
                ", `Channel_ID`" +
                ", `Inviter_ID`" +
                ", `SignUp_Anchor_ID`" +
                ", `SignUp_Anchor_Family_ID`" +
                ", `SignUp_Origin`" +
                ", `SignUp_Date`" +
                ", `SignIn_Origin`" +
                ", `SignIn_Type`" +
                ", `Create_Date`" +
                ", `Create_IP`)" +
                " VALUES(:User_ID" +
                ", :NickName" +
                ", :RealName" +
                ", :IsAnchor" +
                ", :IsFamily" +
                ", :IsAdmin" +
                ", :IsIDCard" +
                ", :IsChargeFirst" +
                ", :Channel_ID" +
                ", :Inviter_ID" +
                ", :SignUp_Anchor_ID" +
                ", :SignUp_Anchor_Family_ID" +
                ", :SignUp_Origin" +
                ", :SignUp_Date" +
                ", :SignIn_Origin" +
                ", :SignIn_Type" +
                ", NOW()" +
                ", :Create_IP);";
            Value = KOC.Lodash.extend({
                User_ID: null,
                NickName: null,
                RealName: null,
                IsAnchor: null,
                IsFamily: null,
                IsAdmin: null,
                IsIDCard: null,
                IsChargeFirst: null,
                Channel_ID: null,
                Inviter_ID: null,
                SignUp_Anchor_ID: null,
                SignUp_Anchor_Family_ID: null,
                SignUp_Origin: null, //注册来源:-1:默认,未知,来源,0-PC,100-安卓,300-IOS
                SignUp_Date: null,
                SignIn_Origin: null, //登录来源:-1:默认,未知,来源,0-PC,100-安卓,300-IOS
                SignIn_Type: null, //登录方式 -1:未知 1:记住 2:用户名 10:QQ 11:微信 12:微博
                Create_IP: null
            }, Value);
            Value.SignUp_Origin = KOC.StringUtils.ToInt(Value.SignUp_Origin, -1);
            Value.SignUp_Date = KOC.DateUtils.Object(Value.SignUp_Date)._d;
            Value.SignIn_Origin = KOC.StringUtils.ToInt(Value.SignIn_Origin, -1);
            Value.SignIn_Type = KOC.StringUtils.ToInt(Value.SignIn_Type, -1);
            Mysql_Helper.ExecuteNonQuery(DBName, sql, Value, callback);
        }
    },
    //endregion
    //region User_Operation:用户操作日志
    User_Operation: {
        Insert: function (Value, callback) {
            var sql = "INSERT INTO `user_operation`" +
                " (`User_ID`" +
                ", `NickName`" +
                ", `RealName`" +
                ", `Function_Code`" +
                ", `Operation`" +
                ", `Related_ID`" +
                ", `Related_URL`" +
                ", `Create_Date`" +
                ", `Create_IP`)" +
                " VALUES(:User_ID" +
                ", :NickName" +
                ", :RealName" +
                ", :Function_Code" +
                ", :Operation" +
                ", :Related_ID" +
                ", :Related_URL" +
                ", NOW()" +
                ", :Create_IP);";
            Value = KOC.Lodash.extend({
                User_ID: null,
                NickName: null,
                RealName: null,
                Function_Code: null,
                Operation: null,
                Related_ID: null,
                Related_URL: null,
                Create_IP: null
            }, Value);
            Mysql_Helper.ExecuteNonQuery(DBName, sql, Value, callback);
        }
    },
    //endregion
    //region Family_Operation:公会操作日志
    Family_Operation: {
        Insert: function (Value, callback) {
            var sql = "INSERT INTO `family_operation`" +
                " (`User_ID`" +
                ", `NickName`" +
                ", `RealName`" +
                ", `Family_ID`" +
                ", `Family_Name`" +
                ", `Function_Code`" +
                ", `Operation`" +
                ", `Related_ID`" +
                ", `Related_URL`" +
                ", `Create_Date`" +
                ", `Create_IP`)" +
                " VALUES(:User_ID" +
                ", :NickName" +
                ", :RealName" +
                ", :Family_ID" +
                ", :Family_Name" +
                ", :Function_Code" +
                ", :Operation" +
                ", :Related_ID" +
                ", :Related_URL" +
                ", NOW()" +
                ", :Create_IP);";
            Value = KOC.Lodash.extend({
                User_ID: null,
                NickName: null,
                RealName: null,
                Family_ID: null,
                Family_Name: null,
                Function_Code: null,
                Operation: null,
                Related_ID: null,
                Related_URL: null,
                Create_IP: null
            }, Value);
            Mysql_Helper.ExecuteNonQuery(DBName, sql, Value, callback);
        }
    },
    //endregion
    //region Admin_Operation:管理员操作日志
    Admin_Operation: {
        Insert: function (Value, callback) {
            var sql = "INSERT INTO `admin_operation`" +
                " (`User_ID`" +
                ", `NickName`" +
                ", `RealName`" +
                ", `Function_Code`" +
                ", `Operation`" +
                ", `Related_ID`" +
                ", `Related_URL`" +
                ", `Create_Date`" +
                ", `Create_IP`)" +
                " VALUES(:User_ID" +
                ", :NickName" +
                ", :RealName" +
                ", :Function_Code" +
                ", :Operation" +
                ", :Related_ID" +
                ", :Related_URL" +
                ", NOW()" +
                ", :Create_IP);";
            Value = KOC.Lodash.extend({
                User_ID: null,
                NickName: null,
                RealName: null,
                Function_Code: null,
                Operation: null,
                Related_ID: null,
                Related_URL: null,
                Create_IP: null
            }, Value);
            Mysql_Helper.ExecuteNonQuery(DBName, sql, Value, callback);
        }
    },
    //endregion


    //region Admin_Log:后台日志写入
    Admin_Log: {
        Insert: function (Value, callback) {
            var sql = "INSERT INTO `admin_log`" +
                " (`Log_Type`" +
                ", `Operate_Type`" +
                ", `Operation`" +
                ", `Related_ID`" +
                ", `Data`" +
                ", `Admin_ID`" +
                ", `RealName`" +
                ", `Phone`" +
                ", `Create_Date`" +
                ", `Create_IP`)" +
                " VALUES(:Log_Type" +
                ", :Operate_Type" +
                ", :Operation" +
                ", :Related_ID" +
                ", :Data" +
                ", :Admin_ID" +
                ", :RealName" +
                ", :Phone" +
                ", NOW()" +
                ", :Create_IP);";
            Value = KOC.Lodash.extend({
                Log_Type: null,
                Operate_Type: null,
                Operation: null,
                Related_ID: null,
                Data: null,
                Admin_ID: null,
                RealName: null,
                Phone: null,
                Create_IP: null
            }, Value);
            Mysql_Helper.ExecuteNonQuery(DBName, sql, Value, callback);
        },
    },
    //endregion
    //region Qcloud_Log:后台日志写入----
    Qcloud_Log: {
        Insert: function (Value, callback) {
            var sql = "INSERT INTO `qcloud_log`" +
                " (`User_ID`" +
                ", `Stream_ID`" +
                ", `EventType`" +
                ", `Time`" +
                ", `Timestamp`" +
                ", `Sign`" +
                ", `Sign_Compare`" +
                ", `Create_Date`)" +
                " VALUES(:User_ID" +
                ", :Stream_ID" +
                ", :EventType" +
                ", :Time" +
                ", :Timestamp" +
                ", :Sign" +
                ", :Sign_Compare" +
                ", NOW());";
            Value = KOC.Lodash.extend({
                User_ID: null,
                Stream_ID: null,
                EventType: null,
                Time: null,
                Timestamp: null,
                Sign: null,
                Sign_Compare: null
            }, Value);
            Mysql_Helper.ExecuteNonQuery(DBName, sql, Value, callback);
        }
    },
    //endregion
    //region Page:分页
    Page: {
        //region UserAdminLog:管理员日志列表---
        UserAdminLog: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnPK = "`admin_log`.`Log_ID`";
            PageParm.ColumnMAX = "`admin_log`.`Log_ID`";
            PageParm.ColumnList = "`admin_log`.`Log_ID`" +
                ", `admin_log`.`Log_Type`" +
                ", `admin_log`.`Operate_Type`" +
                ", `admin_log`.`Operation`" +
                ", `admin_log`.`Data`" +
                ", `admin_log`.`Related_ID`" +
                ", `admin_log`.`Admin_ID`" +
                ", `admin_log`.`RealName`" +
                ", `admin_log`.`Phone`" +
                ", `admin_log`.`Create_Date`" +
                ", `admin_log`.`Create_IP`";
            PageParm.TableList = "`admin_log`";
            if (page.MaxCode && !PageParm.GetPageInfo) {
                parm.MaxCode = page.MaxCode;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, PageParm.ColumnMAX + " <= :MaxCode", "AND");
            }
            if (parm.FuzzyQuery.trim()) {
                parm.FuzzyQueryLike = "%" + parm.FuzzyQuery.trim() + "%";
                var _Condition_FuzzyQuery = "";
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`admin_log`.`Admin_ID` LIKE :FuzzyQueryLike", "OR");
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`admin_log`.`Related_ID` LIKE :FuzzyQueryLike", "OR");
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`admin_log`.`RealName` LIKE :FuzzyQueryLike", "OR");
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`admin_log`.`Phone` LIKE :FuzzyQueryLike", "OR");
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`admin_log`.`Operation` LIKE :FuzzyQueryLike", "OR");
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, _Condition_FuzzyQuery, "AND");
            }
            if (!PageParm.OrderName || PageParm.OrderName == "" || PageParm.OrderName == undefined) {
                PageParm.OrderName = "Create_Date" + " " + "DESC";
            }
            //按Admin_ID查询
            if (parm.Admin_ID) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`admin_log`.`Admin_ID` = :Admin_ID", "AND");
            }
            //按被操作ID查询
            if (parm.Related_ID) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`admin_log`.`Related_ID` = :Related_ID", "AND");
            }
            //按Operation查询
            if (parm.Operation) {
                parm.Operation = "%" + parm.Operation + "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`admin_log`.`Operation` LIKE :Operation", "AND");
            }
            //按RealName查询
            if (parm.RealName) {
                parm.RealName = "%" + parm.RealName + "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`admin_log`.`RealName` LIKE :RealName", "AND");
            }
            //按Phone查询
            if (parm.Phone) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`admin_log`.`Phone` = :Phone", "AND");
            }
            if (parm.Create_Date_Between && parm.Create_Date_And) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "DATE_FORMAT(`admin_log`.`Create_Date`,'%Y-%m-%d') >= :Create_Date_Between AND DATE_FORMAT(`admin_log`.`Create_Date`,'%Y-%m-%d') <= :Create_Date_And", "AND");
            }
            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        UserAdminLog_Parm: function () {
            return {
                FuzzyQuery: "",
                Admin_ID: null,//ID
                Related_ID: null,//被操作人ＩＤ
                RealName: null,//真实姓名
                Phone: null,//手机号
                Log_Type: null,//日志类型
                Operate_Type: null,//操作类型
                Operation: null,//状态
                Create_Date: null,//创建时间
                Create_Date_Between: null,//从....
                Create_Date_And: null//到....
            };
        },
        //endregion
        //region UserLogin:用户登录日志信息
        UserLogin: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnPK = "`Log_ID`";
            PageParm.ColumnMAX = "`Log_ID`";
            PageParm.ColumnList = "*";
            PageParm.TableList = "`user_login`";
            PageParm.Condition = "";
            if (page.MaxCode && !PageParm.GetPageInfo) {
                parm.MaxCode = page.MaxCode;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, PageParm.ColumnMAX + " <= :MaxCode", "AND");
            }
            parm.FuzzyQuery = KOC.StringUtils.ToString(parm.FuzzyQuery);
            if (parm.FuzzyQuery.trim()) {
                parm.FuzzyQueryLike = "%" + parm.FuzzyQuery.trim() + "%";
                var _Condition_FuzzyQuery = "";
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`NickName` LIKE :FuzzyQueryLike", "OR");
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`RealName` = :FuzzyQuery", "OR");
                if (KOC.StringUtils.ToIntPositive(parm.FuzzyQuery)) {
                    _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`User_ID` = :FuzzyQuery", "OR");
                    _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`Log_ID` = :FuzzyQuery", "OR");
                }
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, _Condition_FuzzyQuery, "AND");
            }
            if (parm.Log_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Log_ID` = :Log_ID", "AND");
            }
            if (parm.User_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`User_ID` = :User_ID", "AND");
            }
            if (parm.NickName) {
                parm.NickName = "%" + parm.NickName + "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`NickName` LIKE :NickName", "AND");
            }
            if (parm.RealName) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`RealName` = :RealName", "AND");
            }
            if (parm.Channel_ID) {
                parm.Channel_ID = parm.Channel_ID + "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Channel_ID` LIKE :Channel_ID", "AND");
            }
            if (parm.Inviter_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Inviter_ID` = :Inviter_ID", "AND");
            }
            if (parm.SignUp_Anchor_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`SignUp_Anchor_ID` = :SignUp_Anchor_ID", "AND");
            }
            if (parm.SignUp_Anchor_Family_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`SignUp_Anchor_Family_ID` = :SignUp_Anchor_Family_ID", "AND");
            }
            if (parm.IsAnchor >= 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`IsAnchor` = :IsAnchor", "AND");
            }
            if (parm.IsFamily >= 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`IsFamily` = :IsFamily", "AND");
            }
            if (parm.IsAdmin >= 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`IsAdmin` = :IsAdmin", "AND");
            }
            if (parm.IsIDCard >= 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`IsIDCard` = :IsIDCard", "AND");
            }
            if (parm.IsChargeFirst >= 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`IsChargeFirst` = :IsChargeFirst", "AND");
            }
            if (KOC.Lodash.includes(["Create_Date", "SignUp_Date"], parm.DateType)) {
                parm.StartDate = KOC.DateUtils.Min(parm.StartDate);
                if (parm.StartDate) {
                    PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`" + parm.DateType + "` >= :StartDate", "AND");
                }
                parm.EndDate = KOC.DateUtils.Max(parm.EndDate);
                if (parm.EndDate) {
                    PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`" + parm.DateType + "` <= :EndDate", "AND");
                }
            }
            var _SignUp_Origin = [];
            KOC.Lodash.forEach(String(parm.SignUp_Origin).split(","), function (ThisValue) {
                if (KOC.StringUtils.ToInt(ThisValue, -1) >= 0) {
                    _SignUp_Origin.push(ThisValue);
                }
            });
            if (_SignUp_Origin.length > 0) {
                parm.SignUp_Origin = _SignUp_Origin;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`SignUp_Origin` IN (:SignUp_Origin)", "AND");
            }
            var _SignIn_Origin = [];
            KOC.Lodash.forEach(String(parm.SignIn_Origin).split(","), function (ThisValue) {
                if (KOC.StringUtils.ToInt(ThisValue, -1) >= 0) {
                    _SignIn_Origin.push(ThisValue);
                }
            });
            if (_SignIn_Origin.length > 0) {
                parm.SignIn_Origin = _SignIn_Origin;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`SignIn_Origin` IN (:SignIn_Origin)", "AND");
            }
            var _SignIn_Type = [];
            KOC.Lodash.forEach(String(parm.SignIn_Type).split(","), function (ThisValue) {
                if (KOC.StringUtils.ToInt(ThisValue, -1) >= 0) {
                    _SignIn_Type.push(ThisValue);
                }
            });
            if (_SignIn_Type.length > 0) {
                parm.SignIn_Type = _SignIn_Type;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`SignIn_Type` IN (:SignIn_Type)", "AND");
            }

            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        UserLogin_Parm: function () {
            return {
                FuzzyQuery: "",
                Log_ID: 0,
                User_ID: 0,
                NickName: "",
                RealName: "",
                IsAnchor: -1,
                IsFamily: -1,
                IsAdmin: -1,
                IsIDCard: -1,
                IsChargeFirst: -1,
                Channel_ID: "",
                Inviter_ID: 0,
                SignUp_Anchor_ID: 0,
                SignUp_Anchor_Family_ID: 0,
                SignUp_Origin: "",
                SignIn_Origin: "",
                SignIn_Type: "",
                StartDate: "",
                EndDate: ""
            };
        },
        //endregion
        //region UserOperation:用户操作日志信息
        UserOperation: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnPK = "`Log_ID`";
            PageParm.ColumnMAX = "`Log_ID`";
            PageParm.ColumnList = "*";
            PageParm.TableList = "`user_operation`";
            PageParm.Condition = "";
            if (page.MaxCode && !PageParm.GetPageInfo) {
                parm.MaxCode = page.MaxCode;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, PageParm.ColumnMAX + " <= :MaxCode", "AND");
            }
            parm.FuzzyQuery = KOC.StringUtils.ToString(parm.FuzzyQuery);
            if (parm.FuzzyQuery.trim()) {
                parm.FuzzyQueryLike = "%" + parm.FuzzyQuery.trim() + "%";
                var _Condition_FuzzyQuery = "";
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`NickName` LIKE :FuzzyQueryLike", "OR");
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`RealName` = :FuzzyQuery", "OR");
                if (KOC.StringUtils.ToIntPositive(parm.FuzzyQuery)) {
                    _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`User_ID` = :FuzzyQuery", "OR");
                    _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`Log_ID` = :FuzzyQuery", "OR");
                }
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, _Condition_FuzzyQuery, "AND");
            }
            if (parm.Log_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Log_ID` = :Log_ID", "AND");
            }
            if (parm.User_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`User_ID` = :User_ID", "AND");
            }
            if (parm.NickName) {
                parm.NickName = "%" + parm.NickName + "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`NickName` LIKE :NickName", "AND");
            }
            if (parm.RealName) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`RealName` = :RealName", "AND");
            }
            if (parm.Related_ID) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Related_ID` = :Related_ID", "AND");
            }
            if (parm.Related_URL) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Related_URL` = :Related_URL", "AND");
            }

            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        UserOperation_Parm: function () {
            return {
                FuzzyQuery: "",
                Log_ID: 0,
                User_ID: 0,
                NickName: "",
                RealName: "",
                Related_ID: "",
                Related_URL: "",
                StartDate: "",
                EndDate: ""
            };
        },
        //endregion
        //region UserOperation:公会操作日志信息
        FamilyOperation: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnPK = "`Log_ID`";
            PageParm.ColumnMAX = "`Log_ID`";
            PageParm.ColumnList = "*";
            PageParm.TableList = "`family_operation`";
            PageParm.Condition = "";
            if (page.MaxCode && !PageParm.GetPageInfo) {
                parm.MaxCode = page.MaxCode;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, PageParm.ColumnMAX + " <= :MaxCode", "AND");
            }
            parm.FuzzyQuery = KOC.StringUtils.ToString(parm.FuzzyQuery);
            if (parm.FuzzyQuery.trim()) {
                parm.FuzzyQueryLike = "%" + parm.FuzzyQuery.trim() + "%";
                var _Condition_FuzzyQuery = "";
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`NickName` LIKE :FuzzyQueryLike", "OR");
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`RealName` = :FuzzyQuery", "OR");
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`Family_Name` LIKE :FuzzyQueryLike", "OR");
                if (KOC.StringUtils.ToIntPositive(parm.FuzzyQuery)) {
                    _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`User_ID` = :FuzzyQuery", "OR");
                    _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`Log_ID` = :FuzzyQuery", "OR");
                    _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`Family_ID` = :FuzzyQuery", "OR");
                }
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, _Condition_FuzzyQuery, "AND");
            }
            if (parm.Log_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Log_ID` = :Log_ID", "AND");
            }
            if (parm.User_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`User_ID` = :User_ID", "AND");
            }
            if (parm.NickName) {
                parm.NickName = "%" + parm.NickName + "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`NickName` LIKE :NickName", "AND");
            }
            if (parm.RealName) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`RealName` = :RealName", "AND");
            }
            if (parm.Family_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Family_ID` = :Family_ID", "AND");
            }
            if (parm.Family_Name) {
                parm.Family_Name = "%" + parm.Family_Name + "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Family_Name` LIKE :Family_Name", "AND");
            }
            if (parm.Related_ID) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Related_ID` = :Related_ID", "AND");
            }
            if (parm.Related_URL) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Related_URL` = :Related_URL", "AND");
            }

            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        FamilyOperation_Parm: function () {
            return {
                FuzzyQuery: "",
                Log_ID: 0,
                User_ID: 0,
                NickName: "",
                RealName: "",
                Family_ID: 0,
                Family_Name: "",
                Related_ID: "",
                Related_URL: "",
                StartDate: "",
                EndDate: ""
            };
        },
        //endregion
        //region AdminOperation:管理员操作日志信息
        AdminOperation: function (parm, page, callback) {
            var PageParm = new Mysql_Helper.PageParm();
            PageParm.Cache = page.Cache;
            PageParm.Start = page.Start;
            PageParm.Length = page.Length;
            PageParm.OrderName = page.Sort_Col + " " + page.Sort_Dir;
            PageParm.GetPageInfo = page.GetPageInfo;
            PageParm.ColumnPK = "`Log_ID`";
            PageParm.ColumnMAX = "`Log_ID`";
            PageParm.ColumnList = "*";
            PageParm.TableList = "`admin_operation`";
            PageParm.Condition = "";
            if (page.MaxCode && !PageParm.GetPageInfo) {
                parm.MaxCode = page.MaxCode;
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, PageParm.ColumnMAX + " <= :MaxCode", "AND");
            }
            parm.FuzzyQuery = KOC.StringUtils.ToString(parm.FuzzyQuery);
            if (parm.FuzzyQuery.trim()) {
                parm.FuzzyQueryLike = "%" + parm.FuzzyQuery.trim() + "%";
                var _Condition_FuzzyQuery = "";
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`NickName` LIKE :FuzzyQueryLike", "OR");
                _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`RealName` = :FuzzyQuery", "OR");
                if (KOC.StringUtils.ToIntPositive(parm.FuzzyQuery)) {
                    _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`User_ID` = :FuzzyQuery", "OR");
                    _Condition_FuzzyQuery = Mysql_Helper.AddToWhereSQL(_Condition_FuzzyQuery, "`Log_ID` = :FuzzyQuery", "OR");
                }
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, _Condition_FuzzyQuery, "AND");
            }
            if (parm.Log_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Log_ID` = :Log_ID", "AND");
            }
            if (parm.User_ID > 0) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`User_ID` = :User_ID", "AND");
            }
            if (parm.NickName) {
                parm.NickName = "%" + parm.NickName + "%";
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`NickName` LIKE :NickName", "AND");
            }
            if (parm.RealName) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`RealName` = :RealName", "AND");
            }
            if (parm.Related_ID) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Related_ID` = :Related_ID", "AND");
            }
            if (parm.Related_URL) {
                PageParm.Condition = Mysql_Helper.AddToWhereSQL(PageParm.Condition, "`Related_URL` = :Related_URL", "AND");
            }

            Mysql_Helper.Page(DBName, PageParm, parm, callback);
        },
        AdminOperation_Parm: function () {
            return {
                FuzzyQuery: "",
                Log_ID: 0,
                User_ID: 0,
                NickName: "",
                RealName: "",
                Related_ID: "",
                Related_URL: "",
                StartDate: "",
                EndDate: ""
            };
        }
        //endregion
    }
    //endregion
};